package shopping;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author 29284
 * @since 2024/11/28 20:31
 */
public class ShoppingCart {
    private int capacity;
    private List<Product> products;
    //构造方法

    public ShoppingCart() {
    }

    public ShoppingCart(int capacity) {
        this.capacity = capacity;
        this.products = new ArrayList<Product>();
    }
    public void addProduct(Product product,int num) {
        if (products.size()+num <= capacity) {
            for (int i = 0; i < num; i++) {
                products.add(product);
            }
        }
        else{
            System.out.println("购物车已满，无法添加商品！！！");
        }
    }
    public void removeProduct(Product product) {
        products.remove(product);
    }
    public double getTotalPrice() {
        double totalPrice = 0;
        for (Product product : products) {
            totalPrice +=product.getProductprice();
        }
        return totalPrice;
    }
    public void displayProducts() {
        for (Product product : products) {
            System.out.println("名称："+product.getProductname()+" 价格："+product.getProductprice()+
                    " 类型："+product.getProducttype()+"数量: "+1);}
    }

}
